<template>
  <a-modal
    :visible="visible"
    :title="title"
    :width="800"
    :destroyOnClose="true"
    @ok="() => (this.visible = false)"
    @cancel="() => (this.visible = false)"
  >
    <a-form-model
      class="form-adjust"
      ref="form"
      :model="forms"
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-form-model-item
        label="分类名称"
        prop="name"
        :rules="[{ required: true, message: '请输入分类名称!' }]"
      >
        <a-input
          class="search-input"
          placeholder="请输入分类名称"
          v-model="forms.name"
        />
      </a-form-model-item>
      <a-form-model-item
        label="分类状态"
        prop="status"
        :rules="{ required: true, message: '请选择商品状态!' }"
      >
        <a-radio-group v-model="forms.status">
          <a-radio :value="1">
            启用
          </a-radio>
          <a-radio :value="0">
            禁用
          </a-radio>
        </a-radio-group>
      </a-form-model-item>
<!--      <a-form-model-item
        label="排序"
        prop="orderNum"
        :rules="{ required: true, message: '请输入排序!' }"
      >
        <a-input-number
          placeholder="排序"
          :min="1"
          v-model="forms.orderNum"
        />
      </a-form-model-item>
      <a-form-model-item
        label="状态"
        prop="state"
        :rules="{ required: true, message: '请选择状态!' }"
      >
        <a-radio-group v-model="forms.state">
          <a-radio value="1">
            启用
          </a-radio>
          <a-radio value="0">
            禁用
          </a-radio>
        </a-radio-group>
      </a-form-model-item>-->
    </a-form-model>
    <template slot="footer">
      <a-button type="primary" @click="save()" :disabled="btndisabled" :loading="loading('save')" v-preventReClick:save>
        保存
      </a-button>
      <a-button @click="() => (this.visible = false)" :disabled="btndisabled" :loading="loading('cancel')"
                v-preventReClick:cancel>
        取消
      </a-button>
    </template>
  </a-modal>
</template>
<script>
import {formMixin} from '@/mixins/'
import {add, update} from '@/api/system/permission'
import {getPageList,saveOrUpdate} from "@/api/catalogSort/catalogSort";

export default {
  mixins: [formMixin],
  props: {
    defaultForm: {
      type: Array,
      required: false,
      default: () => {},
    },
  },
  watch: {
    defaultForm: {
      handler(val){
        console.log(val)
      },
      deep: true,
      immediate: true
    }
  },
  data() {
    return {
      disabled: false,
      forms: {},
      title: '',
      visible: false,
      labelCol: {
        xs: {span: 24},
        sm: {span: 5}
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16}
      },
      type: 'add',
      permTypes: [
        {code: '1', name: '商品价格'},
        {code: '2', name: '商品价格'},
        // {code: '3', name: '数据权限'}
      ]
    }
  },
  created() {

  },
  mounted() {
  },
  methods: {
    add(data) {
      // this.forms = Object.assign(
      //   {state: '1', permType: '1', orderNum: 1},
      //   data
      // )
      const temp = {state: '1', permType: '1', orderNum: 1, ...data}
      this.forms = JSON.parse(JSON.stringify(temp))
      this.type = 'add'
    },
    edit(data) {
      this.forms = Object.assign({}, data)
      this.type = 'update'
    },
    save() {
      this.validateForm('form').then(res => {
        if (res) {
          // let call = this.type === 'add' ? add(this.forms) : update(this.forms)
          saveOrUpdate(this.forms).then(response => {
            console.log(response)
            if (response.code == 0){
              this.$emit('success')
              this.visible = false
            }
          })
          // call.then(response => {
          //   if (response.code === 0) {
          //     this.$message.success('保存成功！')
          //     this.$emit('success')
          //     this.visible = false
          //   }
          // })
        }
      })
    }
  }
}
</script>
<style scoped>
.ant-advanced-search-form .ant-form-item {
  display: flex;
}

.fatherBox {
  min-height: 600px;
  background: #fff;
  padding: 20px;
}
</style>
